﻿<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">搜索：</label>
                        <div class="layui-input-inline mr0">
                            <input name="keyword" class="layui-input" type="text" placeholder="输入关键字"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn" lay-filter="formSubSearchCabModule" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button id="btnAddCabModule" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                </div>
            </div>

            <table class="layui-table" id="tableCabModule" lay-filter="tableCabModule"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarCabModule">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="item">配置项</a>
</script>
<!-- 表单弹窗 -->
<script type="text/html" id="modelCabModule">
    <form id="modelCabModuleForm" lay-filter="modelCabModuleForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
		<input name="cabId" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入名称" type="text" class="layui-input" maxlength="50"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">标识</label>
            <div class="layui-input-block">
				<input name="code" placeholder="请输入标识" type="text" class="layui-input" maxlength="50"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">串口号</label>
            <div class="layui-input-block">
				<input name="serialNo" placeholder="请输入标识" type="text" class="layui-input" maxlength="50"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">波特率</label>
            <div class="layui-input-block">
				<input name="baud" placeholder="请输入标识" type="text" class="layui-input" maxlength="50"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
				<select name="type" lay-filter="type">
					<option value="0">a</option>
					<option value="1">b</option>
					<option value="2">c</option>
				</select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">故障</label>
            <div class="layui-input-block">
                <input name="faultBoxs" placeholder="请输入标识" type="text" class="layui-input" maxlength="50" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">使用</label>
            <div class="layui-input-block">
                <input name="usedBoxs" placeholder="请输入标识" type="text" class="layui-input" maxlength="50" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">空闲</label>
            <div class="layui-input-block">
               <input name="freeBoxs" placeholder="请输入标识" type="text" class="layui-input" maxlength="50" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">序号</label>
            <div class="layui-input-block">
                <input name="sort" placeholder="请输入序号" type="number" class="layui-input" min="0" max="1000"
                       lay-verType="tips" lay-verify="required|number" required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="modelSubmitCabModule" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="modelCabModuleBoard">
<form id="modelCabModuleBoardForm" lay-filter="modelCabModuleBoardForm" class="layui-form model-form">
	<input name="id" type="hidden" />
	<input name="moduleId" type="hidden" />
	<div class="layui-form-item">
		<label class="layui-form-label">序列号</label>
		<div class="layui-input-block">
			<input name="serialNo" placeholder="请输入名称" type="text" class="layui-input" maxlength="50" lay-verType="tips"
				lay-verify="required" required />
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">起始位置</label>
		<div class="layui-input-block">
			<input name="startNo" placeholder="请输入标识" type="text" class="layui-input" maxlength="50" lay-verType="tips"
				lay-verify="required" required />
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">结束位置</label>
		<div class="layui-input-block">
			<input name="stopNo" placeholder="请输入标识" type="text" class="layui-input" maxlength="50" lay-verType="tips"
				lay-verify="required" required />
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">总数</label>
		<div class="layui-input-block">
			<input name="total" placeholder="请输入标识" type="text" class="layui-input" maxlength="50" lay-verType="tips"
				lay-verify="required" required />
		</div>
	</div>
	<div class="layui-form-item text-right">
		<button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
		<button class="layui-btn" lay-filter="modelSubmitCabModuleBoard" lay-submit>保存</button>
	</div>
</form>
</script>
<script>
layui.use(['layer', 'form', 'table', 'util', 'admin', 'zTree','treetable', 'config','treeSelect','element'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var config = layui.config;
        var treetable = layui.treetable;
        var treeSelect=layui.treeSelect;
        var config = layui.config;
        var element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
		
		var cabId = '#(cabId)';
        // 渲染表格
        var insTb = table.render({
            elem: '#tableCabModule',
            url: '#(ctx)/biz/cab/module/listData',
            page: true,
            where: {cabId: cabId},
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'},
                {field: 'name', sort: false, title: '名称'},
                {field: 'code', sort: false, title: '标识'},
                {field: 'faultBoxs', sort: false, title: '故障'},
                {field: 'usedBoxs', sort: false, title: '使用'},
                {field: 'freeBoxs', sort: false, title: '空闲'},
/*                 {align: 'center', toolbar: '#tableBarCabModule', title: '操作', minWidth: 180}
 */            ]]
        });

        // 添加
        $('#btnAddCabModule').click(function () {
            showEditModel();
        });

        // 搜索
        form.on('submit(formSubSearchCabModule)', function (data) {
            insTb.reload({where: data.field}, 'data');
        });

        // 工具条点击事件
        table.on('tool(tableCabModule)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
                showEditModel(data);
            } else if (layEvent === 'del') { // 删除
                doDel(obj);
            } else if (layEvent === 'item') {  // 权限管理
                showEditItemModel(data.id);
            }
        });

        // 删除
        function doDel(obj) {
        	layer.confirm('确定要删除“【<span style="color:red;">' +obj.data.name+ '</span>】”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/cab/module/delete', {
                    id: obj.data.id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.message, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                }, 'get');
            });
        }

        // 显示编辑弹窗
        function showEditModel(mCabModule) {
            admin.open({
                type: 1,
                title: (mCabModule ? '修改' : '添加') + '模块',
                content: $('#modelCabModule').html(),
                area:'400px',
                success: function (layero, dIndex) {
                    var url = 'biz/cab/module/save';
                    form.val('modelCabModuleForm', mCabModule);  // 回显数据
                    // 表单提交事件
                    form.on('submit(modelSubmitCabModule)', function (data) {
                        layer.load(2);
                        var formData={}; 
                        for(var key in data.field){
                        	formData['cabModule.'+key]=data.field[key];
                        }
                        formData['cabModule.cabId']=cabId;
                        admin.req(url, formData, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.close(dIndex);
                                layer.msg(res.message, {icon: 1});
                                insTb.reload({}, 'data');
                            } else {
                                layer.msg(res.message, {icon: 2});
                            }
                        }, 'get');
                        return false;
                    });
                    
                }
            });
        }
        
        function showEditItemModel(moduleId) {
        	layer.load(2);
        	var res = common_ajax.ajaxFunc('get','#(ctx)/biz/cab/moduleBoard', {moduleId:moduleId}, 'html', null);
        	
        	layer.closeAll('loading');
			if (!res) {
				layer.alert('系统异常！');
				return;
			}
			
			layer.open({
				id: 'moduleBoard',
				title: '列表内容',
				type: 1,
				area: ['800px', '500px'],
				offset: '100px',
				content: res,
				shade: 0.1,
				skin: 'layui-layer layui-layer-adminRight layui-layer-city',
				success: function(layero, dIndex) {
					$(layero).children('.layui-layer-content').css('overflow', 'hidden');
				},
				end: function() {
				}
			});
        }
        
    });
</script>